package com.hmdp.config;

import com.hmdp.filter.LoginFilter;
import com.hmdp.filter.RefreshTokeFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author LENOVO
 * @Date 2022-11-19
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    /**
     * 注入StringRedis
     */
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 注册拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册 token刷新拦截器

        registry.addInterceptor(new RefreshTokeFilter(stringRedisTemplate))
                .addPathPatterns("/**").order(0);
        //注册 登录拦截器
        registry.addInterceptor(new LoginFilter()).excludePathPatterns(
                "/shop/**",
                "/voucher/**",
                "/shop-type/**",
                "/upload/**",
                "/blog/hot",
                "/user/code",
                "/user/login"
        ).order(1);

    }
}
